<?php
namespace app\home\model;
use think\Model;

class CheckStandardM extends Model{
    protected $table = 'check_standard'; // 设置当前模型对应的完整数据表名称
    protected $pk = 'StandardId';

    // 模型初始化
    protected static function init()
    {
        //TODO:初始化内容
    }

    public function listP($page,$size,$where=''){

        $m = new CheckStandardM();

        $total = CheckStandardM::where($where)->count();
        /*        $list = Db::view('sys_user', '*')
                    ->view('sys_role', '*', 'sys_user.RoleId=sys_role.RoleId')
                    ->view('sys_department', 'DeptId,DeptNO,DeptName', 'sys_user.DeptId=sys_department.DeptId')
                    ->where('UserState','=','Y')->paginate($size,$total);*/
        $list =$m->where($where)
            ->page($page,$size)
            ->order('CreateTime desc')
            ->select();
//        lasd();
        // 过滤post数组中的非数据表字段数据
        return [
            'total'=>$total,
            'page'=>$page,
            'size'=>$size,
            'list'=>$list
        ];
    }
    public function all(){
        $res = CheckStandardM::select();
        // 过滤post数组中的非数据表字段数据
        return $res;
    }

    public function addOne(){
        $data = input('post.');
        $data['Creator'] = session('user.UserId');
        $m = new CheckStandardM($data);
        // 过滤post数组中的非数据表字段数据
        return $m->allowField(true)->save();
    }

    public function editOne(){
        $data = input('post.');
        $data['Updater'] = session('user.UserId');
        $data['UpdateTime'] = date('Y-m-d H:i:s', time());
        $m = new CheckStandardM();
        // 过滤post数组中的非数据表字段数据
        return $m->allowField(true)->update($data);
//  条件修改      return $sup->allowField(true)->save(input('post.'),['c_id' => input('post.id')]);
    }
    public function delOne(){
        return CheckStandardM::destroy(input($this->pk));
// 支持批量删除多个数据 User::destroy('1,2,3');
// 或者 User::destroy([1,2,3]);
    }


}